/*
 * Copyright (C) 2013 Daniel Treffenstädt <daniel@treffenstaedt.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#include "OInput.h"

O_START_NAMESPACE



KeyEvent::KeyCode Input::toKey(OIS::KeyCode kc)
{/*
	switch (kc)
	{
	case OIS::KC_ESCAPE:
		return KeyEvent::KeyCode::Esc;
		break;
	case OIS::KC_1:
		return KeyEvent::KeyCode::One;
		break;
	case OIS::KC_2:
		return KeyEvent::KeyCode::Two;
		break;
	case OIS::KC_3:
		return KeyEvent::KeyCode::Three;
		break;
	case OIS::KC_4:
		return KeyEvent::KeyCode::Four;
		break;
	case OIS::KC_5:
		return KeyEvent::KeyCode::Five;
		break;
	case OIS::KC_6:
		return KeyEvent::KeyCode::Six;
		break;
	case OIS::KC_7:
		return KeyEvent::KeyCode::Seven;
		break;
	case OIS::KC_8:
		return KeyEvent::KeyCode::Eight;
		break;
	case OIS::KC_9:
		return KeyEvent::KeyCode::Nine;
		break;
	case OIS::KC_0:
		return KeyEvent::KeyCode::Zero;
		break;
	case OIS::KC_A:
		return KeyEvent::KeyCode::A;
		break;
	case OIS::KC_B:
		return KeyEvent::KeyCode::B;
		break;
	case OIS::KC_C:
		return KeyEvent::KeyCode::C;
		break;
	case OIS::KC_D:
		return KeyEvent::KeyCode::D;
		break;
	case OIS::KC_E:
		return KeyEvent::KeyCode::E;
		break;
	case OIS::KC_F:
		return KeyEvent::KeyCode::F;
		break;
	case OIS::KC_G:
		return KeyEvent::KeyCode::G;
		break;
	case OIS::KC_H:
		return KeyEvent::KeyCode::H;
		break;
	case OIS::KC_I:
		return KeyEvent::KeyCode::I;
		break;
	case OIS::KC_J:
		return KeyEvent::KeyCode::J;
		break;
	case OIS::KC_K:
		return KeyEvent::KeyCode::K;
		break;
	case OIS::KC_L:
		return KeyEvent::KeyCode::L;
		break;
	case OIS::KC_M:
		return KeyEvent::KeyCode::M;
		break;
	case OIS::KC_N:
		return KeyEvent::KeyCode::N;
		break;
	case OIS::KC_O:
		return KeyEvent::KeyCode::O;
		break;
	case OIS::KC_P:
		return KeyEvent::KeyCode::P;
		break;
	case OIS::KC_Q:
		return KeyEvent::KeyCode::Q;
		break;
	case OIS::KC_R:
		return KeyEvent::KeyCode::R;
		break;
	case OIS::KC_S:
		return KeyEvent::KeyCode::S;
		break;
	case OIS::KC_T:
		return KeyEvent::KeyCode::T;
		break;
	case OIS::KC_U:
		return KeyEvent::KeyCode::U;
		break;
	case OIS::KC_V:
		return KeyEvent::KeyCode::V;
		break;
	case OIS::KC_W:
		return KeyEvent::KeyCode::W;
		break;
	case OIS::KC_X:
		return KeyEvent::KeyCode::X;
		break;
	case OIS::KC_Y:
		return KeyEvent::KeyCode::Y;
		break;
	case OIS::KC_Z:
		return KeyEvent::KeyCode::Z;
		break;
	case OIS::KC_F1:
		return KeyEvent::KeyCode::F1;
		break;
	case OIS::KC_F2:
		return KeyEvent::KeyCode::F2;
		break;
	case OIS::KC_F3:
		return KeyEvent::KeyCode::F3;
		break;
	case OIS::KC_F4:
		return KeyEvent::KeyCode::F4;
		break;
	case OIS::KC_F5:
		return KeyEvent::KeyCode::F5;
		break;
	case OIS::KC_F6:
		return KeyEvent::KeyCode::F6;
		break;
	case OIS::KC_F7:
		return KeyEvent::KeyCode::F7;
		break;
	case OIS::KC_F8:
		return KeyEvent::KeyCode::F8;
		break;
	case OIS::KC_F9:
		return KeyEvent::KeyCode::F9;
		break;
	case OIS::KC_F10:
		return KeyEvent::KeyCode::F10;
		break;
	case OIS::KC_F11:
		return KeyEvent::KeyCode::F11;
		break;
	case OIS::KC_F12:
		return KeyEvent::KeyCode::F12;
		break;
	case OIS::KC_F13:
		return KeyEvent::KeyCode::F13;
		break;
	case OIS::KC_F14:
		return KeyEvent::KeyCode::F14;
		break;
	case OIS::KC_F15:
		return KeyEvent::KeyCode::F15;
		break;
	case OIS::KC_NUMPAD0:
		return KeyEvent::KeyCode::;
		break;
	case OIS::KC_NUMPAD1:
		return KeyEvent::KeyCode::;
		break;
	case OIS::KC_NUMPAD2:
		return KeyEvent::KeyCode::;
		break;
	case OIS::KC_NUMPAD3:
		return KeyEvent::KeyCode::;
		break;
	case OIS::KC_NUMPAD4:
		return KeyEvent::KeyCode::;
		break;
	case OIS::KC_:
		return KeyEvent::KeyCode::;
		break;
	case OIS::KC_:
		return KeyEvent::KeyCode::;
		break;
	case OIS::KC_:
		return KeyEvent::KeyCode::;
		break;
	default:
		return KeyEvent::KeyCode::None;
		break;
	}

	KC_MINUS       = 0x0C,    // - on main keyboard
	KC_EQUALS      = 0x0D,
	KC_BACK        = 0x0E,    // backspace
	KC_TAB         = 0x0F,
	KC_LBRACKET    = 0x1A,
	KC_RBRACKET    = 0x1B,
	KC_RETURN      = 0x1C,    // Enter on main keyboard
	KC_SEMICOLON   = 0x27,
	KC_APOSTROPHE  = 0x28,
	KC_GRAVE       = 0x29,    // accent
	KC_BACKSLASH   = 0x2B,
	KC_COMMA       = 0x33,
	KC_PERIOD      = 0x34,    // . on main keyboard
	KC_SLASH       = 0x35,    // / on main keyboard
	KC_RSHIFT      = 0x36,
	KC_MULTIPLY    = 0x37,    // * on numeric keypad
	KC_SPACE       = 0x39,
	KC_CAPITAL     = 0x3A,
	KC_NUMLOCK     = 0x45,
	KC_SCROLL      = 0x46,    // Scroll Lock
	KC_NUMPAD7     = 0x47,
	KC_NUMPAD8     = 0x48,
	KC_NUMPAD9     = 0x49,
	KC_SUBTRACT    = 0x4A,    // - on numeric keypad
	KC_NUMPAD4     = 0x4B,
	KC_NUMPAD5     = 0x4C,
	KC_NUMPAD6     = 0x4D,
	KC_ADD         = 0x4E,    // + on numeric keypad
	KC_NUMPAD1     = 0x4F,
	KC_NUMPAD2     = 0x50,
	KC_NUMPAD3     = 0x51,
	KC_NUMPAD0     = 0x52,
	KC_DECIMAL     = 0x53,    // . on numeric keypad
	KC_OEM_102     = 0x56,    // < > | on UK/Germany keyboards)
	KC_KANA        = 0x70,    // (Japanese keyboard)
	KC_ABNT_C1     = 0x73,    // / ? on Portugese (Brazilian) keyboards
	KC_CONVERT     = 0x79,    // (Japanese keyboard)
	KC_NOCONVERT   = 0x7B,    // (Japanese keyboard)
	KC_YEN         = 0x7D,    // (Japanese keyboard)
	KC_ABNT_C2     = 0x7E,    // Numpad . on Portugese (Brazilian) keyboards
	KC_NUMPADEQUALS= 0x8D,    // = on numeric keypad (NEC PC98)
	KC_PREVTRACK   = 0x90,    // Previous Track (KC_CIRCUMFLEX on Japanese keyboard)
	KC_AT          = 0x91,    //                     (NEC PC98)
	KC_COLON       = 0x92,    //                     (NEC PC98)
	KC_UNDERLINE   = 0x93,    //                     (NEC PC98)
	KC_KANJI       = 0x94,    // (Japanese keyboard)
	KC_STOP        = 0x95,    //                     (NEC PC98)
	KC_AX          = 0x96,    //                     (Japan AX)
	KC_UNLABELED   = 0x97,    //                        (J3100)
	KC_NEXTTRACK   = 0x99,    // Next Track
	KC_NUMPADENTER = 0x9C,    // Enter on numeric keypad
	KC_MUTE        = 0xA0,    // Mute
	KC_CALCULATOR  = 0xA1,    // Calculator
	KC_PLAYPAUSE   = 0xA2,    // Play / Pause
	KC_MEDIASTOP   = 0xA4,    // Media Stop
	KC_VOLUMEDOWN  = 0xAE,    // Volume -
	KC_VOLUMEUP    = 0xB0,    // Volume +
	KC_WEBHOME     = 0xB2,    // Web home
	KC_NUMPADCOMMA = 0xB3,    // , on numeric keypad (NEC PC98)
	KC_DIVIDE      = 0xB5,    // / on numeric keypad
	KC_SYSRQ       = 0xB7,
	KC_PAUSE       = 0xC5,    // Pause
	KC_HOME        = 0xC7,    // Home on arrow keypad
	KC_UP          = 0xC8,    // UpArrow on arrow keypad
	KC_PGUP        = 0xC9,    // PgUp on arrow keypad
	KC_LEFT        = 0xCB,    // LeftArrow on arrow keypad
	KC_RIGHT       = 0xCD,    // RightArrow on arrow keypad
	KC_END         = 0xCF,    // End on arrow keypad
	KC_DOWN        = 0xD0,    // DownArrow on arrow keypad
	KC_PGDOWN      = 0xD1,    // PgDn on arrow keypad
	KC_INSERT      = 0xD2,    // Insert on arrow keypad
	KC_DELETE      = 0xD3,    // Delete on arrow keypad
	KC_APPS        = 0xDD,    // AppMenu key
	KC_POWER       = 0xDE,    // System Power
	KC_SLEEP       = 0xDF,    // System Sleep
	KC_WAKE        = 0xE3,    // System Wake
	KC_WEBSEARCH   = 0xE5,    // Web Search
	KC_WEBFAVORITES= 0xE6,    // Web Favorites
	KC_WEBREFRESH  = 0xE7,    // Web Refresh
	KC_WEBSTOP     = 0xE8,    // Web Stop
	KC_WEBFORWARD  = 0xE9,    // Web Forward
	KC_WEBBACK     = 0xEA,    // Web Back
	KC_MYCOMPUTER  = 0xEB,    // My Computer
	KC_MAIL        = 0xEC,    // Mail
	KC_MEDIASELECT = 0xED     // Media Select
	*/
}

KeyEvent::Modifier Input::toModifier(OIS::KeyCode kc)
{
	switch (kc)
	{
	case OIS::KC_LSHIFT:
		return KeyEvent::Modifier::ShiftL;
		break;
	case OIS::KC_RSHIFT:
		return KeyEvent::Modifier::ShiftR;
		break;
	case OIS::KC_LCONTROL:
		return KeyEvent::Modifier::CtrlL;
		break;
	case OIS::KC_RCONTROL:
		return KeyEvent::Modifier::CtrlR;
		break;
	case OIS::KC_LWIN:
		return KeyEvent::Modifier::MetaL;
		break;
	case OIS::KC_RWIN:
		return KeyEvent::Modifier::MetaR;
		break;
	case OIS::KC_LMENU:
		return KeyEvent::Modifier::AltL;
		break;
	case OIS::KC_RMENU:
		return KeyEvent::Modifier::AltR;
		break;
	default:
		return KeyEvent::Modifier::None;
		break;
	}
}

MouseEvent::Button Input::toButton(OIS::MouseButtonID mb)
{
	switch (mb)
	{
	case OIS::MB_Left:
		return MouseEvent::Button::Left;
		break;
	case OIS::MB_Right:
		return MouseEvent::Button::Right;
		break;
	case OIS::MB_Middle:
		return MouseEvent::Button::Middle;
		break;
	case OIS::MB_Button3:
		return MouseEvent::Button::Button3;
		break;
	case OIS::MB_Button4:
		return MouseEvent::Button::Button4;
		break;
	case OIS::MB_Button5:
		return MouseEvent::Button::Button5;
		break;
	case OIS::MB_Button6:
		return MouseEvent::Button::Button6;
		break;
	case OIS::MB_Button7:
		return MouseEvent::Button::Button7;
		break;
	default:
		return MouseEvent::Button::None;
		break;
	}
}

Input::Input(Window* win)
{
	m_window	= win;

	m_mouse->setEventCallback(this);
	m_keyboard->setEventCallback(this);
}

void Input::pollEvents()
{
	m_keyboard->capture();
	m_mouse->capture();
}

bool Input::keyPressed(const OIS::KeyEvent &evt)
{

}

bool Input::keyReleased(const OIS::KeyEvent &evt)
{

}

bool Input::mouseMoved(const OIS::MouseEvent& evt)
{

}

bool Input::mousePressed(const OIS::MouseEvent& evt, OIS::MouseButtonID id)
{

}

bool Input::mouseReleased(const OIS::MouseEvent& evt, OIS::MouseButtonID id)
{

}

O_END_NAMESPACE
